Android
How connect device and module
The device integration API allows to integrate with existing and new data types of Huma SDK. The data type is an abstract entity that represents a specific type of data that can be collected from a device and submitted to a module. Huma SDK defines several data types that are used by 1st party modules. Developers can define their own data types in their custom modules.
How to use predefined data types
class MyDevice : DeviceIntegration {
override val supportedModuleDataTypes: List<KClass<out ModuleDataType<*>>> =
listOf(BloodPressureModuleDataType::class)
}
When you declare one or more predefined module data types from
kotlin com.huma.sdk.module_kit.ability.generic
package, no extra steps required.
How to add new data type and connect device and module
There might be a case where you have your custom module and you want to add support for your device.
1. Create custom DataType
data class MyDataType(
override val data: MyData,
override val timestamp: Long,
override val source: String?,
) : ModuleDataType<MyModuleDataType.MyData> {
data class MyData(
val field1: Int,
val field2: Int,
)
}
2. Add your MyDataType
to your device
class MyDevice : DeviceIntegration {
override val supportedModuleDataTypes: List<KClass<out ModuleDataType<*>>> =
listOf(MyDataType::class)
}
3. Add your MyDataType
to your module
class MyModule : BaseModule(),
/* any other extra module dependencies */,
ModuleWithDeviceIntegration, //define that your module supports device integration
ModuleWithDataTypeInput, //define that your module supports data type input
ModuleWithResult<MyResult> //(optional) define the result data api.
// It is used out of the scope for this feature,
//but device integration relays on results api to get the required
//range for background and foreground data refresh {
{
override val dataTypes: List<KClass<out ModuleDataType<*>>>
get() = listOf(MyDataType::class)
override val dataTypeToModuleResultConverters: List<(ModuleDataType<*>) -> ModuleInputResult?>
get() = listOf(MyDataTypeToValueConverter())
private val deviceSyncDelegate = DeviceSyncDelegate.get(this)
override val extraButtons: List<ExtraButton>
get() = listOfNotNull(
deviceSyncDelegate.syncButton(resources)
/* Your other buttons, if there is any */
)
}
Where MyDataTypeToValueConverter
is a converter that converts generic data type to a module
specific input.
How to submit device data
To submit device data your device flow should call a submitData
from
HumaModuleKitManager
.
HumaModuleKitManager.getInstance().submitData(
dataType = MyDataType(),
//(optional) This parameter is used to define app behaviour during submission flow
params = ModuleInputSubmitParams(...),
//(optiona) This parameter is used to submit data to a specific module rather then all the modules that supports passed data type.
moduleConfigId = "moduleConfigId",
//(optiona) This parameter is used to submit data to a specific module rather then all the modules that supports passed data type.
moduleId = "moduleId",
//(optiona) This parameter is used to submit data to a specific module rather then all the modules that supports passed data type.
moduleClass = MyModule::class,
)
All optional parameter can be passed or skipped. Each parameter except params
is used to
filter out the modules where data will be submitted. If all fields are null, SDK will find and
submit the dataType
to all modules that are listed as supported for provided data type.